#!/bin/sh
#
# "You're the One for me, fatty" (Morrissey)
# Test if a given file is Fat Binary / Universal Binary
#
# Return code: 0 for yes or 1 for no, 2 for error
#

PROGNAME=$(basename $0)
OSX="snowleopard"

while getopts "hls" OPTION ; do
    case $OPTION in
	h)
	    echo "Test if a given file is Fat Binary / Universal Binary"
	    echo "Usage: $PROGNAME [-h|-s|-l] /path/to/binary"
	    echo "  -h  This help"
	    echo "  -l  Test as if Mac OS X is Leopard"
	    echo "  -s  Test as if Mac OS X is Snow Leopard (default)"
	    echo "Return code: 0 for yes, 1 for no, 2 for error"
	    exit 2
	    ;;
	l)
	    OSX="leopard"
	    ;;
	s)
	    OSX="snowleopard"
	    ;;
	?)
	    exit 2
	    ;;
    esac
done

shift $(($OPTIND-1)) # skip options
if [ "$1" = "" ] ; then
    echo "Usage: $PROGNAME [-h|-s|-l] /path/to/binary"
    exit 2
fi

case $OSX in
    leopard)
	lipo $* -verify_arch i386 ppc7400 || lipo $1 -verify_arch i386 ppc
	;;
    snowleopard)
	lipo $* -verify_arch x86_64 i386
	;;
    *)
	exit 2
	;;
esac
